package com.assistant.codegen.modules.template.domain;

import com.assistant.framework.BaseDomain;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Map;

/**
 * 模版
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "codegen_template_template")
public class Template extends BaseDomain<Template> {

    /**
     * 模版名称
     */
    private String name;

    /**
     * 模版引擎
     */
    private TemplateEngine engine;

    /**
     * 文件路径的模式
     */
    private String filePathPattern;

    /**
     * 文件名称的模式
     */
    private String fileNamePattern;

    /**
     * 文件内容的模式
     */
    @Column(name = "content_pattern", columnDefinition = "text")
    private String contentPattern;

    public String getFilePath(Map<String, Object> context) {
        return this.engine.resolver.apply(this.filePathPattern, context);
    }

    public String getFileName(Map<String, Object> context) {
        return this.engine.resolver.apply(this.fileNamePattern, context);
    }

    public String getContent(Map<String, Object> context) {
        return this.engine.resolver.apply(this.contentPattern, context);
    }
}
